import urllib
import chardet
""" 
from chardet.universaldetector import UniversalDetector

usock = urllib.urlopen('http://yahoo.co.jp/')
detector = UniversalDetector()
for line in usock.readlines():
    detector.feed(line)
    if detector.done: break
detector.close()
usock.close()
print (detector.result) 
"""
print(chardet.detect(b'Hello, world!'))
data = '离离原上草，一岁一枯荣'.encode('gbk')
# data = '离离原上草，一岁一枯荣'.encode('utf-8')
# data = '最新の主要ニュース'.encode('euc-jp')
print(chardet.detect(data))